# 二进制文件
# 写入
import struct

file = open("D:/python_game/learning_2.txt", "wb")

for n in range(1000):
    data = struct.pack('i', n)
    file.write(data)
file.close()

# 读取
file = open("D:/python_game/learning_2.txt", "rb")
size = struct.calcsize("i")
bytes_read = file.read(size)

while bytes_read:
    value = struct.unpack("i", bytes_read)
    value = value[0]
    print(value, end=" ")
    bytes_read = file.read(size)

file.close()
